package com.denlaku.longan.qo;

import com.denlaku.longan.core.Current;
import lombok.Data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * @author tianx
 */
@Data
public class Query {
    private Long id;
    private List<Long> ids;
    private List<Long> permTagIds;
    private String keyword;
    private Long tenantId;
    private Long currUserId;

    protected Query() {
        this.tenantId = Current.getTenantId();
        this.currUserId = Current.getUserId();
    }

    public static Query of(Long id) {
        Query query = new Query();
        query.setTenantId(Current.getTenantId());
        query.setCurrUserId(Current.getUserId());
        query.setId(id);
        return query;
    }

    public static Query of(Long tenantId, Long id) {
        Query query = new Query();
        query.setTenantId(tenantId);
        query.setId(id);
        return query;
    }

    public static Query of(Set<Long> ids) {
        return of(Current.getTenantId(), ids);
    }

    public static Query of(Long tenantId, Set<Long> ids) {
        Query query = new Query();
        query.setTenantId(tenantId);
        query.setIds(new ArrayList<>(ids));
        Collections.sort(query.getIds());
        return query;
    }

}
